package com.kingdee.eas.zssh.project.app;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.framework.CoreBillBaseInfo;
import com.kingdee.eas.framework.util.FilterUtility;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.eas.xinrui.publicbill.AuditStateEnum;
import com.kingdee.eas.zssh.project.AssignmentBillInfo;

public class AssignmentBillControllerBean extends AbstractAssignmentBillControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.zssh.project.app.AssignmentBillControllerBean");
    protected IObjectPK _submit(Context ctx, IObjectValue model)throws BOSException, EASBizException {
    	AssignmentBillInfo info = (AssignmentBillInfo)model;
		info.setState(AuditStateEnum.audited);
		info.setAuditor(ContextUtil.getCurrentUserInfo(ctx));
    	return super._submit(ctx, model);
    }
	protected void _unAudit(Context ctx, IObjectValue model)throws BOSException {
		super._unAudit(ctx, model);
		AssignmentBillInfo info = (AssignmentBillInfo)model;
		info.setState(AuditStateEnum.save);
		info.setAuditor(null);
		try {
			_update(ctx,new ObjectUuidPK(info.getId()),info);
		} catch (EASBizException e) {
			e.printStackTrace();
		}
	}


protected IObjectPK _addnew(Context ctx, IObjectValue model)
    throws BOSException, EASBizException
{
//	CoreBillBaseInfo info = (CoreBillBaseInfo)model;
//    info.setCU(super.getCU(ctx, info));
//	_checkNumberDup(ctx, model);
    return super._addnew(ctx, model);
}

protected void _addnew(Context ctx, IObjectPK pk, IObjectValue model)
    throws BOSException, EASBizException
{
//	CoreBillBaseInfo info = (CoreBillBaseInfo)model;
//    info.setCU(super.getCU(ctx, info));
//	_checkNumberDup(ctx, model);
    super._addnew(ctx, pk, model);
}
	protected boolean _checkNumberDup(Context ctx,  IObjectValue model)
    throws EASBizException, BOSException
	{
	    CoreBillBaseInfo coreBillBaseInfo = (CoreBillBaseInfo)model;
	    FilterInfo filter = new FilterInfo();
	    FilterItemInfo filterItem = new FilterItemInfo("number", coreBillBaseInfo.getString("number"), CompareType.EQUALS);
	    filter.getFilterItems().add(filterItem);
	    if(coreBillBaseInfo.getId() != null)
	    {
	        filter.getFilterItems().add(new FilterItemInfo("id", coreBillBaseInfo.getId().toString(), CompareType.NOTEQUALS));
	        filter.setMaskString("#0 and #1");
	    }
	    if(FilterUtility.hasFilterItem(getFilterForCheckNumber(coreBillBaseInfo)))
	        filter.mergeFilter(getFilterForCheckNumber(coreBillBaseInfo), "AND");
	    if(super._exists(ctx, filter))
	        throw new EASBizException(EASBizException.CHECKDUPNUMBER, new Object[] {
	            coreBillBaseInfo.getString("number"), ""
	        });
	    else
	        return true;
	}
	protected void _editAssment(Context ctx, IObjectValue model)
			throws BOSException {
		
	}
}